<template>
    <!-- 访客 -->
    <div class="visitor box">
        <div class="title">
            <div class="left">
                <img src="images/home/visitor.svg">
                <b>访客</b>
            </div>
            <div class="right" @click="handleClickMore()">更多
                <van-icon name="arrow" />
            </div>
        </div>
        <div class="content">
            <div class="left" @click="handleClick('/convaccess/visitorApproval')">
                <h5>
                    待审批访客
                    <span class="tip" v-if="approvalNum">{{approvalNum}}</span>
                </h5>
                <p>审批人员</p>
                <div class="iconImg">
                    <img src="images/home/visitorApproval.svg" />
                </div>
            </div>
            <div class="right">
                <ul>
                    <li @click="handleClick('/convaccess/appointmentVisit')">
                        <h5>预约拜访</h5>
                        <p>预约前来拜访人员</p>
                        <div class="iconImg">
                            <img src="images/home/appointmentVisit.svg" />
                        </div>
                    </li>
                    <li @click="handleClick('/convaccess/myInvitation')">
                        <h5>我要邀请</h5>
                        <p>发起来访邀请</p>
                        <div class="iconImg">
                            <img src="images/home/invite.svg" />
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
    import { pageForMyApproval } from '@/api/srvAssurance/convaccess/visitorApproval';

    export default {
        data () {
            return {
                approvalNum: 0
            }
        },
        created () {
            this.pageForMyApprovalData();
        },
        methods: {
            // 点击进入应用
            handleClick (path) {
                if (!path) return;
                this.$router.push({ path });
                this.$emit('sendAccesslog', path);
            },
            // 点击更多
            handleClickMore () {
                sessionStorage.removeItem('activeApply');
                this.$router.push({ path: '/mainFrame/apply?menuName=访客预约' });
            },
            // 获取待审批数量
            pageForMyApprovalData () {
                let params = {
                    pageNum: 1,
                    pageSize: 1
                }
                pageForMyApproval(params).then(res => {
                    if (res.code === 1000 && res.data) {
                        this.approvalNum = res.data.total;
                    }
                })
            }
        }
    }
</script>

<style scoped lang="less">
    .title {
        line-height: 40px;
        display: flex;
        justify-content: space-between;
        line-height: 24px;
        margin: 20px 0 8px 0;
        .left {
            font-size: 18px;
            color: #283f65;
            img {
                width: 24px;
                height: 24px;
                margin-right: 4px;
                vertical-align: top;
            }
        }
        .right {
            font-size: 12px;
            color: #9ba5b8;
        }
    }
    .box {
        padding: 0 12px;
        box-sizing: border-box;
        h5 {
            font-size: 14px;
            line-height: 24px;
            margin-bottom: 4px;
            color: #283f65;
        }
        p {
            font-size: 12px;
            line-height: 16px;
            color: #9ba5b8;
        }
        ul {
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;
            li {
                width: 48.5%;
                height: 68px;
                margin-bottom: 8px;
                border-radius: 8px;
                padding-left: 16px;
                padding-top: 10px;
                box-sizing: border-box;
                position: relative;
            }
        }
        .iconImg {
            position: absolute;
            right: 0;
            bottom: 0;
            img {
                width: 100%;
                height: 100%;
            }
        }
    }
    .visitor .content {
        display: flex;
        justify-content: space-between;
        & > div {
            flex: 1;
            ul li {
                height: 60px;
                width: 100%;
                background: linear-gradient(90deg, #f9e4e0 0%, #fff6f4 100%);
            }
            ul li:nth-of-type(2) {
                margin-bottom: 0;
                background: linear-gradient(90deg, #e1eaff 0%, #f1f4ff 100%);
            }
        }
        .left {
            background: linear-gradient(180deg, #d0f0f5 0%, #f0fdff 100%);
            border-radius: 8px;
            margin-right: 8px;
            padding-left: 16px;
            padding-top: 24px;
            box-sizing: border-box;
            position: relative;
            h5 {
                position: relative;
                .tip {
                    position: absolute;
                    min-width: 16px;
                    padding: 0 4px;
                    box-sizing: border-box;
                    height: 16px;
                    line-height: 17px;
                    top: -4px;
                    background: #fc5039;
                    border-radius: 10px 10px 10px 0px;
                    color: #ffffff;
                    font-size: 10px;
                    margin-left: 7px;
                }
            }
            .iconImg {
                width: 80px;
                height: 80px;
            }
        }
        .right .iconImg {
            width: 58px;
            height: 55px;
        }
    }
</style>